# -*- coding: utf-8  -*-
#!/usr/local/bin/python

__author__ = 'jian.yao'

import logging
import traceback
from django.conf import settings

class SysLogger(object):
    def __init__(self):
        super(SysLogger, self).__init__()

    loggername_log_related = settings.PROJECT_LOG_RELATED
    loggername_exception_related = settings.PROJECT_EXCEPTION_RELATED

    @classmethod
    def debug(cls, msg):
        _logger = logging.getLogger(cls.loggername_log_related)
        if _logger:
            extra = {"realLocation" : repr(traceback.format_stack(limit=2)[0])}
            _logger.debug(msg, extra=extra)

    @classmethod
    def info(cls, msg):
        _logger = logging.getLogger(cls.loggername_log_related)
        if _logger:
            extra = {"realLocation" : repr(traceback.format_stack(limit=2)[0])}
            _logger.info(msg, extra=extra)

    @classmethod
    def warn(cls, msg):
        _logger = logging.getLogger(cls.loggername_log_related)
        if _logger:
            extra = {"realLocation" : repr(traceback.format_stack(limit=2)[0])}
            _logger.warn(msg, extra=extra)

    @classmethod
    def error(cls, msg):
        _logger = logging.getLogger(cls.loggername_log_related)
        if _logger:
            extra = {"realLocation" : repr(traceback.format_stack(limit=2)[0])}
            _logger.error(msg, extra=extra)

    @classmethod
    def exception(cls, exp):
        _logger = logging.getLogger(cls.loggername_log_related)
        if _logger:
            extra = {"realLocation" : repr(traceback.format_stack(limit=2)[0])}
            _logger.error(exp, extra=extra)

        _logger = logging.getLogger(cls.loggername_exception_related)
        if _logger:
            _logger.exception(exp)